﻿using Jay.Sc2.Bof.Lib.State;

namespace Jay.Sc2.Bof.Lib.Action.Terran
{
	class ActionProduceThor : ActionProduceTerran
	{
		public static ActionProduceThor Instance = new ActionProduceThor();

		private ActionProduceThor() : base(60, 300, 200, 6) { }

		public override int AvailableProducer(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return (state.FactoryTechLab.AvailableForProduction);
		}

		public override bool HaveTechnology(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return state.Armory.Count > 0 && state.FactoryTechLab.Count > 0;
		}

		public override bool IsInvalid(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return base.IsInvalid(bo) || state.FactoryTechLab.Total == 0 || state.Armory.Total == 0;
		}

		public void OnProductionFinished(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			state.Thor++;
		}

		public override void Execute(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			base.Execute(bo);
			state.FactoryTechLab.Production++;
			bo.AddAction(state.Time + BuildTime, new ActionGeneric("ActionSpawnThor", (ActionGeneric.ActionExecuteDelegate)delegate(IBuildOrder ibo)
			{
				TerranState ibostate = ibo.State as TerranState;
				ibostate.FactoryTechLab.Production--;
				OnProductionFinished(ibo);
			}));
		}

		private IAction[,] m_Requirements;
		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
				{
					m_Requirements = new IAction[,] { 
						{ ActionProduceTechLabOnFactory.Instance, ActionProduceArmory.Instance }, 
						{ ActionSwitchTechLabFromBarracksToFactory.Instance, ActionProduceArmory.Instance }, 
						{ ActionSwitchTechLabFromStarportToFactory.Instance, ActionProduceArmory.Instance }, 
					};
				}
				return m_Requirements;
			}
		}
	}
}
